package com.shanxi.cz.module.biz.dal.mysql.ammeterrecordmonth;

import cn.idev.excel.util.StringUtils;
import com.shanxi.cz.framework.common.pojo.PageResult;
import com.shanxi.cz.framework.mybatis.core.mapper.BaseMapperX;
import com.shanxi.cz.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.shanxi.cz.module.biz.controller.admin.ammeterrecordmonth.vo.AmmeterRecordMonthPageReqVO;
import com.shanxi.cz.module.biz.dal.dataobject.ammeterrecordday.AmmeterRecordDayDO;
import com.shanxi.cz.module.biz.dal.dataobject.ammeterrecordmonth.AmmeterRecordMonthDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 电表数据日报 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface AmmeterRecordMonthMapper extends BaseMapperX<AmmeterRecordMonthDO> {

    default PageResult<AmmeterRecordMonthDO> selectPage(AmmeterRecordMonthPageReqVO reqVO) {
        LambdaQueryWrapperX<AmmeterRecordMonthDO> wrapperX = new LambdaQueryWrapperX<AmmeterRecordMonthDO>()
                .eqIfPresent(AmmeterRecordMonthDO::getAmmeterId, reqVO.getAmmeterId())
                .eqIfPresent(AmmeterRecordMonthDO::getRecordMonth, reqVO.getRecordMonth())
                .eqIfPresent(AmmeterRecordMonthDO::getHz, reqVO.getHz())
                .eqIfPresent(AmmeterRecordMonthDO::getVoltageA, reqVO.getVoltageA())
                .eqIfPresent(AmmeterRecordMonthDO::getVoltageB, reqVO.getVoltageB())
                .eqIfPresent(AmmeterRecordMonthDO::getVoltageC, reqVO.getVoltageC())
                .eqIfPresent(AmmeterRecordMonthDO::getElectricityA, reqVO.getElectricityA())
                .eqIfPresent(AmmeterRecordMonthDO::getElectricityB, reqVO.getElectricityB())
                .eqIfPresent(AmmeterRecordMonthDO::getElectricityC, reqVO.getElectricityC())
                .eqIfPresent(AmmeterRecordMonthDO::getPower, reqVO.getPower())
                .eqIfPresent(AmmeterRecordMonthDO::getEng, reqVO.getEng())
                .betweenIfPresent(AmmeterRecordMonthDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AmmeterRecordMonthDO::getId);
        if (StringUtils.isNotBlank(reqVO.getRecordMonthFrom()) && StringUtils.isNotBlank(reqVO.getRecordMonthTo())) {
            wrapperX.betweenIfPresent(AmmeterRecordMonthDO::getRecordMonth, new String[]{reqVO.getRecordMonthFrom(), reqVO.getRecordMonthTo()});
        }
        return selectPage(reqVO, wrapperX);
    }

    default List<AmmeterRecordMonthDO> selectList(AmmeterRecordMonthPageReqVO pageReqVO) {
        return selectList(new LambdaQueryWrapperX<AmmeterRecordMonthDO>()
                .eqIfPresent(AmmeterRecordMonthDO::getAmmeterId, pageReqVO.getAmmeterId())
                .likeIfPresent(AmmeterRecordMonthDO::getRecordMonth, pageReqVO.getRecordMonth())
                .orderByDesc(AmmeterRecordMonthDO::getCreateTime));
    }
}